using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Callista.TFSBuildAlert
{
    internal class Settings
    {
        public static string TFSServer
        {
            get { return GetSetting("TFSServer"); }
            set { UpdateSetting("TFSServer", value); }
        }

        public static string AlertCommand
        {
            get { return GetSetting("AlertCommand"); }
            set { UpdateSetting("AlertCommand", value); }
        }

        public static string ResetCommand
        {
            get { return GetSetting("ResetCommand"); }
            set { UpdateSetting("ResetCommand", value); }
        }

        private static string GetSetting(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }

        private static void UpdateSetting(string key, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings.Remove(key);
            config.AppSettings.Settings.Add(key, value);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
    }
}
